<?php
namespace Wxapps\Controller;
use Think\Controller;

class UserController extends Controller{
    /**
     * 用户自动登录
     * @return array
     * @throws \app\common\exception\BaseException
     * @throws \think\Exception
     * @throws \think\exception\DbException
     */
    public function login()
    {
        $model = D('Users');
        $user_data = $model->login($_POST);
        _apiReturn(1,'success',[
            'user_data' => $user_data,
            'wechat_reg' => $user_data['wechat_reg'],
            'user_id' => $user_data['id'],
            'token' => $model->getToken()
        ]);
    }

    /**
     * 当前用户详情
     * @return array
     * @throws \app\common\exception\BaseException
     * @throws \think\exception\DbException
     */
    public function detail()
    {
        if (!$token = $_REQUEST['token']) {
            _apiReturn(0,'缺少必要的参数：token');
        }
        $model = D('Users');
        if (!$user = $model->getUser($token)) {
            _apiReturn(0,'没有找到用户信息');
        }
        _apiReturn(1,'success',$user);
    }

    /**
     * 修改手机号码
     */
    public function update_mobile(){
        $model = D('Users');
        $model->_update_mobile($_REQUEST);
    }

    /**
     * 修改个人信息
     */
    public function update(){
        $model = D('Users');
        $model->_update($_REQUEST);
    }
    /**
     * 微信账号绑定
     */
    public function bing_wechat_user(){
        $model = D('Users');
        $model->_bing_wechat_user($_REQUEST);
    }

    /**
     * 手机号快速验证
     */
    public function check_phone_number(){
        if(!$_REQUEST['code'] || !$_REQUEST['uid']){
            _apiReturn(0,'缺少参数～');
        }
        $model = D('Users');
        $model->_check_phone_number($_REQUEST);
    }
    
}